<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class UserProjectPivotTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_project_pivot', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id')->index()->comment('用户ID');
            $table->unsignedInteger('project_id')->index()->comment('项目ID');
            $table->unsignedInteger('company_id')->index()->comment('公司ID');
            $table->string('type')->comment('关系类型');
            $table->timestamp('start')->nullable()->comment('开始时间');
            $table->timestamp('end')->nullable()->comment('开始时间');
            $table->timestamps();
            $table->unique(['user_id', 'type']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_project_pivot');
    }
}
